package com.ztewatch.wearcontacts.view;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ztewatch.wearcontacts.R;

public class BaseGridViewAdapter extends BaseAdapter {
	public static final String ITEM_IMAGE = "item_image";
	public static final String ITEM_TEXT = "item_text";
	public static final String IS_DISABLE_FALG = "is_enable_flag";
	private List<HashMap<String, Object>> list;
	private LayoutInflater mInflater;

	public BaseGridViewAdapter(Context context,
			List<HashMap<String, Object>> list) {
		this.list = list;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = mInflater.inflate(R.layout.grid_item, null);
		ImageView mImageView = (ImageView) convertView
				.findViewById(R.id.item_image);
		TextView mTextView = (TextView) convertView
				.findViewById(R.id.item_text);

		mImageView.setImageResource((Integer) list.get(position)
				.get(ITEM_IMAGE));
		mTextView.setText((CharSequence) list.get(position).get(ITEM_TEXT));
		Object object = list.get(position).get(IS_DISABLE_FALG);
		if (object != null && ((boolean)object)) {
			mImageView.setEnabled(false);
			mTextView.setEnabled(false);
			convertView.setOnClickListener(null);
		} else {
			mImageView.setEnabled(true);
			mTextView.setEnabled(true);
		}
		return convertView;
	}

}
